package com.wsoft.config;

import com.wsoft.entity.TsJobEntity;
import com.wsoft.enums.JobStatusEnum;
import com.wsoft.system.manager.TsJobManager;
import com.wsoft.query.job.JobListQuery;
import com.wsoft.system.service.impl.TsJobServiceImpl;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 任务初始化
 * @Author z001
 * @Date 2024/11/21 11:03
 */
@Component
public class TaskInitializer implements CommandLineRunner {
    @Resource
    private TsJobManager jobManager;
    @Resource
    private TsJobServiceImpl jobService;

    @Override
    public void run(String... args) throws Exception {
        JobListQuery jobListQuery = new JobListQuery();
        jobListQuery.setStatus(JobStatusEnum.START.getType());
        // 查询数据库中的任务
        List<TsJobEntity> taskList = jobManager.listJob(jobListQuery);

        for (TsJobEntity task : taskList) {
            jobService.startCronJob(task);
        }
    }
}
